const defaultState = {
  inputValue: "123",
  list: [1, 2],
};
// eslint-disable-next-line import/no-anonymous-default-export
export default (state = defaultState, action) => {
  const { type, data, index } = action;
  const newState = JSON.parse(JSON.stringify(state));
  console.log(action);
  switch (type) {
    case "change":
      console.log(data);

      newState.inputValue = data;

      return newState;
    case "addlist":
      console.log("add");
      // const newState = JSON.parse(JSON.stringify(state));

      newState.list.push(newState.inputValue);
      console.log(newState.list);
      newState.inputValue = "";
      return newState;
    case "deleteitem":
      newState.list.splice(index, 1);
      return newState;
    case "init":
      console.log("init");
      newState.list = data;
      return newState;
    case "change_inputv":
      newState.inputValue = action.value;
      return newState;

    case "change_list":
      newState.list.push(newState.inputValue);
// return [inputValue,...state]
      newState.inputValue = "";
      return newState;
case "change_del":
  newState.list.splice(index, 1);
  return newState;
    default:
      return state;
  }
};
